package us.quizgame.quiz;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.Timer;

import us.quizgame.Menu;
import us.quizgame.ScoreCard;
import us.quizgame.database.Question;

public class SurvivalQuizGame extends QuizGame
{
	/**
	 * Launch the application.
	 */
	
	public static void main(String[] args)
	{
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					QuizGame frame = new SurvivalQuizGame();
					frame.setVisible(true);
					frame.setLocationRelativeTo(null);
				} catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
	}
	
	@Override
	protected void correctAnswer(JButton button)
	{
		super.correctAnswer(button);
		resetQuestionTimerStart();
	}
	
	@Override 
	protected void wrongAnswer(JButton button)
	{
		button.setText("Wrong!");
		button.setBackground(Color.red);
		mainTimer.stop();
		endGame();
	}
	
	@Override
	protected void timeOut()
	{
		System.out.println("Time out");
		setDisabled();
		button1.setText("Time out!");
		button2.setText("Time out!");
		button1.setBackground(Color.red);
		button2.setBackground(Color.red);
		mainTimer.stop();
		endGame();
	}
	
	@Override
	protected void endGame()
	{
		mainTimer.stop();
		//ScoreCard scoreCard = new ScoreCard(totalGameTime, score, "survival");
		if (score < 3)
			playSound(Menu.class.getResource("/us/quizgame/media/Denied.wav"));
		
		ScoreCard scoreCard = new ScoreCard(this);
		scoreCard.setVisible(true);
		dispose();
		this.setVisible(false);
	
	}
	
	public SurvivalQuizGame()
	{
		super();
		gameMode = "survival";
		
		
	}
	
	@Override
	public Question[] getQuestions() {
		Question[] newQuestions = new Question[questionSub + 1];
		
		for (int i = 0; i <= questionSub; i++)
		{
			newQuestions[i] = questions[i];
		}
		
		return newQuestions;
	}
	
	

}
